package day3.Bum;

import day3.Bum.Bum;

/**
 * ClassName：Producer
 *
 * @Author：小鱼
 * @Create：2025-08-20 11:35
 */
public class Producer extends Thread{
    public Bum bum;

    public Producer(String name,Bum bum){
        super(name);
        this.bum = bum;
    }

    @Override
    public void run(){
        for (int i = 1; i <= 100; i++) {
            //生产包子
            synchronized (bum){
                if(bum.flag){
                    //如果有包子，不蒸包子
                    try {
                        bum.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                    System.out.println("第"+i+"次，生产包子");
                    bum.num+=2;
                    System.out.println("包子数量："+bum.num);
                    bum.flag = true;
                    bum.notify();

            }
        }

    }

}
